<?php
/**
 * Created by PhpStorm.
 * User: yangxiaolin
 * Date: 2017/4/26
 * Time: 11:03
 */

namespace App\Services;


use Illuminate\Support\Facades\Log;

trait HttpRequestServices
{
    public function createRequest($url,$PostData=null,$IsPost=false){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //curl_setopt($ch, CURL_SSLVERSION_SSL, 2);
        if($IsPost===true){
            curl_setopt($ch,CURLOPT_POST, 1);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$PostData);
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $data = curl_exec($ch);
        $logs = [
            'url' => $url,
            'data' => $PostData,
            'result' => $data,
        ];
        Log::info(json_encode($logs,JSON_UNESCAPED_UNICODE));
        return $data;
    }
}